package com.csi.sai.bl.dataview;

import java.util.ArrayList;

import javax.sql.DataSource;

import com.csi.sai.data.entities.Candidato;
import com.csi.sai.utilities.Utilities;
import com.csi.sai.utilities.templates.reports.CandidateDialogTemplate;
import com.csi.sai.utilities.templates.reports.InnerCandidateTemplate;

public class GetDataViewRelationship extends GetDataView {
	private String headerHTML;
	private String bodyHTML;

	public GetDataViewRelationship(DataSource ds) {
		super(ds);
	}

	@Override
	protected void writeHeaders() {
		headerHTML = InnerCandidateTemplate.headers;
	}

	@Override
	protected <T> void writeBody(Generics<T> object) {
		ArrayList<Candidato> candidateList = (ArrayList<Candidato>)object.getObject();
		StringBuffer sb = new StringBuffer();
		for(int index=0; index<candidateList.size(); index++) {
			Candidato candidato = (Candidato)candidateList.get(index);
			String row = InnerCandidateTemplate.row;
			row = row.replace("{candidate}", ""+candidato.getIdCandidate()).
						replace("{nombre}", candidato.getNombreCandidato()).
						replace("{creacion}", Utilities.getDateByFormat(candidato.getFechaAlta(), Utilities.formatView)).
						replace("{source}", candidato.getFuente()).
						replace("{skill}", candidato.getSkill()).
						replace("{estatus}", candidato.getEstatus()).
						replace("{cv}", candidato.getCurriculum()).
						replace("{index}", ""+index);
			sb.append(row);
		}
		
		bodyHTML = InnerCandidateTemplate.body.replace("{body}", sb.toString());
	}

	@Override
	public String getHTMLCode() {
		return headerHTML.replace("{body}", bodyHTML);
	}

}
